jQuery(function($) {
	init();
	showBook(url, data);
	
//	buttonStaticBookClick();
});
	
function init() {
	initData();
	
	var grid_selector = "#grid-table";
	var pager_selector = "#grid-pager";

	jQuery(grid_selector).jqGrid({
		//direction: "rtl",
		data: grid_data,
		datatype: "local",
		height: 250,
		colNames:['Operation', 'ID','Name', 'Borrowed', 'Remarks'],
		colModel:[
			{name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false,
				formatter:'actions', 
				formatoptions:{ 
					keys:true,
					
					delOptions:{recreateForm: true, beforeShowForm:beforeDeleteCallback},
					editformbutton:true, editOptions:{recreateForm: true, beforeShowForm:beforeEditCallback}
				}
			},
			
			{name:'id',index:'id', width:60, sorttype:"int", editable: true},
			
			{name:'name',index:'name', width:240,editable: true,editoptions:{size:"20",maxlength:"30"}},
			{name:'borrowed',index:'borrowed', width:70, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"},unformat: aceSwitch},
			
			{name:'remarks',index:'remarks', width:240, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"10"}} 
		], 

		viewrecords : true,
		rowNum:10,
		rowList:[10,20,30],
		pager : pager_selector,
		altRows: true,
		//toppager: true,
		
		multiselect: true,
		//multikey: "ctrlKey",
		multiboxonly: true,

		loadComplete : function() {
			var table = this;
			setTimeout(function(){
				styleCheckbox(table);
				
				updateActionIcons(table);
				updatePagerIcons(table);
				enableTooltips(table);
			}, 0);
		},

		editurl: $path_base+"/dummy.html",//nothing is saved
		caption: "图书信息",
		autowidth: true
	});
	
	//enable search/filter toolbar
	//jQuery(grid_selector).jqGrid('filterToolbar',{defaultSearch:true,stringResult:true})

	//navButtons
	jQuery(grid_selector).jqGrid('navGrid',pager_selector,
		{
			// navbar options
			edit: true,
			editicon : 'icon-pencil blue',
			add: true,
			addicon : 'icon-plus-sign purple',
			del: true,
			delicon : 'icon-trash red',
			search: true,
			searchicon : 'icon-search orange',
			refresh: true,
			refreshicon : 'icon-refresh green',
			view: true,
			viewicon : 'icon-zoom-in grey',
		},
		{
			// edit record form
			// closeAfterEdit: true,
			recreateForm: true,
			beforeShowForm : function(e) {
				var form = $(e[0]);
				form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
				style_edit_form(form);
			}
		},
		{
			// new record form
			closeAfterAdd: true,
			recreateForm: true,
			viewPagerButtons: false,
			beforeShowForm : function(e) {
				var form = $(e[0]);
				form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
				style_edit_form(form);
			}
		},
		{
			// delete record form
			recreateForm: true,
			beforeShowForm : function(e) {
				var form = $(e[0]);
				if(form.data('styled')) return false;
				
				form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
				style_delete_form(form);
				
				form.data('styled', true);
			},
			onClick : function(e) {
				alert(1);
			}
		},
		{
			// search form
			recreateForm: true,
			afterShowSearch: function(e){
				var form = $(e[0]);
				form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
				style_search_form(form);
			},
			afterRedraw: function(){
				style_search_filters($(this));
			},
			multipleSearch: true,
			/**
			multipleGroup:true,
			showQuery: true
			*/
		},
		{
			//view record form
			recreateForm: true,
			beforeShowForm: function(e){
				var form = $(e[0]);
				form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
			}
		}
	)
	
	initThisPageAfter();
}

function initData() {
	grid_data = [ ];
	data = {};
	data['page'] = {page:1, num:10};
	data['method'] = "getAllBookByPage";
	url = "/openresource-client/book/getAllBookByPage";
}

function initThisPageAfter() {
	$(".ui-jqgrid .ui-jqgrid-bdiv").height("0px");
	
	$("#add_grid-table .ui-icon").removeClass("icon-plus-sign").removeClass("purple");
	$("#add_grid-table .ui-icon").css("width", "18px");
	$("#add_grid-table .ui-icon").html("<img id='ui-icon-trash' src='../assets/css/images/user-ui-icon-zoom-in-grey.png' width='18' height='20' vertical-align='center' />");
	
	$("#edit_grid-table .ui-icon").removeClass("icon-pencil").removeClass("blue");
	$("#edit_grid-table .ui-icon").css("width", "18px");
	$("#edit_grid-table .ui-icon").html("<img id='ui-icon-trash' src='../assets/css/images/user-ui-icon-pencil-blue.png' width='18' height='20' vertical-align='center' />");
	
	$("#view_grid-table .ui-icon").removeClass("icon-zoom-in").removeClass("grey");
	$("#view_grid-table .ui-icon").css("width", "18px");
	$("#view_grid-table .ui-icon").html("<img id='ui-icon-trash' src='../assets/css/images/user-ui-icon-plus-sign-purple.png' width='18' height='20' vertical-align='center' />");
	
	$("#del_grid-table .ui-icon").removeClass("icon-trash").removeClass("red");
	$("#del_grid-table .ui-icon").css("width", "18px");
	$("#del_grid-table .ui-icon").html("<img id='ui-icon-trash' src='../assets/css/images/user-ui-icon-trash-red.png' width='18' height='20' vertical-align='center' />");
	
	$("#search_grid-table .ui-icon").removeClass("icon-search").removeClass("orange");
	$("#search_grid-table .ui-icon").css("width", "18px");
	$("#search_grid-table .ui-icon").html("<img id='ui-icon-trash' src='../assets/css/images/user-ui-icon-search-orange.png' width='18' height='20' vertical-align='center' />");
	
	$("#refresh_grid-table .ui-icon").removeClass("icon-refresh").removeClass("green");
	$("#refresh_grid-table .ui-icon").css("width", "18px");
	$("#refresh_grid-table .ui-icon").html("<img id='ui-icon-trash' src='../assets/css/images/user-ui-icon-refresh-green.png' width='18' height='20' vertical-align='center' />");
	
	$("#first_grid-pager").html("<span class='ui-icon' style='margin-top:5px' ><<</span>");
	$("#prev_grid-pager").html("<span class='ui-icon'><</span>");
	$("#next_grid-pager").html("<span class='ui-icon'>></span>");
	$("#last_grid-pager").html("<span class='ui-icon'>>></span>");
	
	$("#first_grid-pager").removeClass("ui-state-disabled");
	$("#prev_grid-pager").removeClass("ui-state-disabled");

	$("#jEditButton_1").html("<span class='ui-icon'>>></span>");
}

function initDynamicComponentVal() {
	
}
	
function initDynamicComponentEvent() {
	$("#add_grid-table").unbind("click");
	$("#edit_grid-table").unbind("click");
	$("#view_grid-table").unbind("click");
	$("#del_grid-table").unbind("click");
	$("#search_grid-table").unbind("click");
	$("#refresh_grid-table").unbind("click");
	
	$('#grid-table td').unbind("click");
	
	$("#sData").unbind();
	
	$("#sData").unbind().click(function(){
		alert('sData');
	});
	
	$(".ui-pg-selbox").unbind().click(function(){
		jAlert($(".ui-pg-selbox").val());
	});
	
	$('#add_grid-table span').on(ace.click_event, function () {
		showBookAddDialog();
	});
}

function buttonInEditDialog() {
	$("#borrowed").unbind().click(function() {
		if($("#borrowedHidden").val() == "true") {
			$("#borrowedHidden").val("false");
		} else {
			$("#borrowedHidden").val("true");
		}
	});
	
	$("#bookEditSubmit").unbind().click(function() {
		var bookEditSubmitData = {};
		
		bookEditSubmitData["book.id"] = $("#id").val();
		bookEditSubmitData["book.name"] = $("#name").val();
		bookEditSubmitData["book.borrowed"] = $("#borrowedHidden").val();
		bookEditSubmitData["book.remarks"] = $("#remarks").val();
		
		// do we need page.page or page.size for the updateBook controller?
		bookEditSubmitData["page.page"] = $("#grid-pager_center .ui-pg-input").val();
		bookEditSubmitData["page.size"] = 10;
		
		var bookEditSubmitUrl = "/openresource-client/book/updateBook?method=updateBook";
		
		$.ajax({
			url: bookEditSubmitUrl,
			type: "POST",
			data: confirmData(bookEditSubmitData),
			dataType: "json",
			error:function(data) {
				alert("request error");
			},
			success: function(mydata) {
				refreshBookPage($("#grid-pager_center .ui-pg-input").val());
				
				$.alerts._hide();
				Mask.Close();
			}
		});
	});

	$("#bookEditCancel").unbind().click(function() {
		$.alerts._hide();
		Mask.Close();
	});
	
	$("#bookAddSubmit").unbind().click(function() {
		var bookAddSubmitData = {};
		
		bookAddSubmitData["book.id"] = $("#id").val();
		bookAddSubmitData["book.name"] = $("#name").val();
		bookAddSubmitData["book.borrowed"] = $("#borrowedHidden").val();
		bookAddSubmitData["book.remarks"] = $("#remarks").val();
		
		bookAddSubmitData["page.page"] = $("#grid-pager_center .ui-pg-input").val();
		bookAddSubmitData["page.size"] = 10;
		
		var bookAddSubmitUrl = "/openresource-client/book/addBook?method=addBook";
		
		$.ajax({
			url: bookAddSubmitUrl,
			type: "POST",
			data: confirmData(bookAddSubmitData),
			dataType: "json",
			error:function(data) {
				alert("request error");
			},
			success: function(mydata) {
				refreshBookPage(1);
				
				$.alerts._hide();
				Mask.Close();
			}
		});
	});
	
	$("#bookAddCancel").unbind().click(function() {
		$.alerts._hide();
		Mask.Close();
	});
}

function showBook(url, data) {
	initBookTable();
	
	Mask.Loading();
	$.ajax({
		url: url,
		type: "GET",
		data: confirmData(data),
		dataType: "json",
		success: function(mydata) {
//			var j = 0;
//			var strstr = "";
			
			if (mydata.bookVo.bookArray[0].name == null || mydata.bookVo.bookArray[0].name == "") {
				alert("no records");
				$("#grid-pager_center .ui-pg-input").val(1);
				$("#sp_1_grid-pager").html(1);
				drawpages(1, 1);
				Mask.Close();
			} else {
				drawBookList(mydata);
				pageClick(url, "bookTable", data, mydata.bookVo.page.size);
				Mask.Close();
			}
		}
	});
}

function initBookTable() {
	// define table raw seletion
	selectRowFlag = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	selectTableBookId = new Array(11);
	deleteBookFlag = 0;
//	$("#del_grid-table").attr("disabled", true);
//	$("#edit_grid-table .ui-icon").html("");
	$("#del_grid-table .ui-icon").html("");
	$("#edit_grid-table .ui-icon").html("");

}

//switch element when editing inline
function aceSwitch( cellvalue, options, cell ) {
	setTimeout(function(){
		$(cell).find('input[type=checkbox]')
			.wrap('<label class="inline" />')
			.addClass('ace ace-switch ace-switch-5')
			.after('<span class="lbl"></span>');
	}, 0);
}
//enable datepicker
function pickDate( cellvalue, options, cell ) {
	setTimeout(function(){
		$(cell) .find('input[type=text]')
				.datepicker({format:'yyyy-mm-dd' , autoclose:true}); 
	}, 0);
}
function style_edit_form(form) {
	//enable datepicker on "sdate" field and switches for "stock" field
	form.find('input[name=sdate]').datepicker({format:'yyyy-mm-dd' , autoclose:true})
		.end().find('input[name=stock]')
			  .addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>');

	//update buttons classes
	var buttons = form.next().find('.EditButton .fm-button');
	buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
	buttons.eq(0).addClass('btn-primary').prepend('<i class="icon-ok"></i>');
	buttons.eq(1).prepend('<i class="icon-remove"></i>')
	
	buttons = form.next().find('.navButton a');
	buttons.find('.ui-icon').remove();
	buttons.eq(0).append('<i class="icon-chevron-left"></i>');
	buttons.eq(1).append('<i class="icon-chevron-right"></i>');		
}

function style_delete_form(form) {
	var buttons = form.next().find('.EditButton .fm-button');
	buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
	buttons.eq(0).addClass('btn-danger').prepend('<i class="icon-trash"></i>');
	buttons.eq(1).prepend('<i class="icon-remove"></i>')
}

function style_search_filters(form) {
	form.find('.delete-rule').val('X');
	form.find('.add-rule').addClass('btn btn-xs btn-primary');
	form.find('.add-group').addClass('btn btn-xs btn-success');
	form.find('.delete-group').addClass('btn btn-xs btn-danger');
}
function style_search_form(form) {
	var dialog = form.closest('.ui-jqdialog');
	var buttons = dialog.find('.EditTable')
	buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'icon-retweet');
	buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'icon-comment-alt');
	buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'icon-search');
}

function beforeDeleteCallback(e) {
	var form = $(e[0]);
	if(form.data('styled')) return false;
	
	form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
	style_delete_form(form);
	
	form.data('styled', true);
}

function beforeEditCallback(e) {
	var form = $(e[0]);
	form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
	style_edit_form(form);
}



//it causes some flicker when reloading or navigating grid
//it may be possible to have some custom formatter to do this as the grid is being created to prevent this
//or go back to default browser checkbox styles for the grid
function styleCheckbox(table) {
/**
	$(table).find('input:checkbox').addClass('ace')
	.wrap('<label />')
	.after('<span class="lbl align-top" />')

	$('.ui-jqgrid-labels th[id*="_cb"]:first-child')
	.find('input.cbox[type=checkbox]').addClass('ace')
	.wrap('<label />').after('<span class="lbl align-top" />');
*/
}


//unlike navButtons icons, action icons in rows seem to be hard-coded
//you can change them like this in here if you want
function updateActionIcons(table) {
	/**
	var replacement = 
	{
		'ui-icon-pencil' : 'icon-pencil blue',
		'ui-icon-trash' : 'icon-trash red',
	'ui-icon-disk' : 'icon-ok green',
	'ui-icon-cancel' : 'icon-remove red'
	};

	$(table).find('.ui-pg-div span.ui-icon').each(function(){
		var icon = $(this);
		var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
		if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
	})
	*/
}

//replace icons with FontAwesome icons like above
function updatePagerIcons(table) {
	var replacement = 
	{
//		'ui-icon-seek-first' : 'icon-double-angle-left bigger-140',
//		'ui-icon-seek-prev' : 'icon-angle-left bigger-140',
//		'ui-icon-seek-next' : 'icon-angle-right bigger-140',
//		'ui-icon-seek-end' : 'icon-double-angle-right bigger-140'
		'ui-icon-seek-first' : '',
		'ui-icon-seek-prev' : '',
		'ui-icon-seek-next' : '',
		'ui-icon-seek-end' : ''
	};
	$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function(){
		var icon = $(this);
		var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
		
		if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
	})
	
	initData();
}

function enableTooltips(table) {
	$('.navtable .ui-pg-button').tooltip({container:'body'});
	$(table).find('.ui-pg-div').tooltip({container:'body'});
}

function drawBookList(mydata) {
//	$(".ui-jqgrid-htable tr:not(:first-child)").remove();
	$(".ui-jqgrid-htable tr").remove();
	$("#sp_1_grid-pager").html(mydata.bookVo.page.size);
	var str = bookTableHearder;
	
	var id = "";
	var name = "";
	var borrowed = "";
	var remarks = "";
	var rowClass = "";
	
	for(var i = 0; i < mydata.bookVo.bookArray.length; i ++) {
		
		if(mydata.bookVo.bookArray[i] == null || mydata.bookVo.bookArray[i].name == null || mydata.bookVo.bookArray[i].name == "") {
			break;
		}
		
		id = truncate(mydata.bookVo.bookArray[i].id, 0);
		name = truncate(mydata.bookVo.bookArray[i].name, 0);
		borrowed = truncate(mydata.bookVo.bookArray[i].borrowed, 0);
		
		remarks = truncate(mydata.bookVo.bookArray[i].remarks, 0);
		
		if(i%2 == 1) {
			rowClass = "ui-widget-content jqgrow ui-row-ltr ui-priority-secondary";
		} else {
			rowClass = "ui-widget-content jqgrow ui-row-ltr";
		}
		
		str += 
			"<tr role='row' id='25' tabindex='-1' class='" + rowClass + "'>" + 
		"<td role='gridcell' style='text-align:center;width: 25px;' aria-describedby='grid-table_cb'><input role='checkbox' type='checkbox' id='jqg_grid-table_25' class='cbox' name='jqg_grid-table_25'></td>" + 
		
		"<td role='gridcell' style='' title='' aria-describedby='grid-table_myac'>" + 
			"<div style='margin-left:8px;'><div title='' style='float:left;cursor:pointer;' class='ui-pg-div ui-inline-edit' id='jEditButton_" + id + "' onclick='showBookEditDialog(this);' onmouseover='jQuery(this).addClass(\"" + "ui-state-hover" + "\");' onmouseout='jQuery(this).removeClass(\"" + "ui-state-hover" + "\");' data-original-title='Edit selected row'>" + 
				"<img id='ui-icon-edit' src='../assets/css/images/user-ui-icon-pencil.png' width='16' height='16' vertical-align='right' />" +
			"</div>" + 
			"<div title='' style='float:left;margin-left:5px;cursor:pointer;' class='ui-pg-div ui-inline-del' id='jDeleteButton_" + i + "' onclick='deleteBookById(this)' onmouseover='jQuery(this).addClass(\"" + "ui-state-hover" + "\");' onmouseout='jQuery(this).removeClass(\"" + "ui-state-hover" + "\");' data-original-title='Delete selected row'>" + 
				"<img id='ui-icon-trash' src='../assets/css/images/ui-icon-trash.png' width='16' height='16' vertical-align='right' />" +
			"</div>" + 
		"</td>" + 

		"<td role='gridcell' style='' title='24' aria-describedby='grid-table_id' class='table_td_class_book_id'>" + id + "</td>" + 
		"<td role='gridcell' style='' title='Speakers' aria-describedby='grid-table_name'>" + name + "</td>" + 
		"<td role='gridcell' style='' title='No' aria-describedby='grid-table_borrowed'>" + borrowed + "</td>" + 
		"<td role='gridcell' style='' title='uploaded by steve' aria-describedby='grid-table_remarks'>" + remarks + "</td>" + 
	"</tr>";
	}
	jQuery(".ui-jqgrid-htable").append(str);
	
	drawBookRawColor();
	drawpages(mydata.bookVo.page.page, mydata.bookVo.page.size);
	initDynamicComponentVal();
	initDynamicComponentEvent();
}

function drawBookRawColor() {
	$(".ui-jqgrid-htable tr:odd").addClass("odd");
	$(".ui-jqgrid-htable tr:even").addClass("even");
	$(".ui-jqgrid-htable tr").mouseover(function(){
		$(this).addClass('mouseover')
		.end();
	});
	
	$(".ui-jqgrid-htable tr").mouseout(function(){
		$(this).removeClass('mouseover')
		.end();
	});
	
	$(".ui-jqgrid-htable input:checkbox").click(function(){
		
		var selectRowNum = parseInt($(".ui-jqgrid-htable input:checkbox").index(this));
		var selectedBookId = $(this).parent().parent().children(".table_td_class_book_id").html();
		
		var selectedRow = $(this).parent().parent();
		
		if (0 == selectRowFlag[selectRowNum]) {
			deleteBookFlag = 1;
			selectRowFlag[selectRowNum] = 1;
			selectTableBookId[selectRowNum] = parseInt(selectedBookId);
			selectedRow.addClass("selected")
			.end();
		} else {
			selectRowFlag[selectRowNum] = 0;
			selectTableBookId[selectRowNum] = 0;
			selectedRow.removeClass("selected")
			.end();
		}
		
//		alert("here");
		changeBookSelectFlag();
//		alert("here1");
		changeBookTableButton();
		getAllSelectedBookId();
	});
}

function changeBookSelectFlag() {
	
	var sum = getSelectRowSum();
	
	if (1 == sum) {
		deleteBookFlag = 1;
	} else {
		deleteBookFlag = 0;
	}
}

function getSelectRowSum() {
	var sum = 0;
	for(var i = 1; i < 11; i ++) {
		sum += selectRowFlag[i];
	}
	return sum;
}
function getAllSelectedBookId() {
	var sum = "";
	for(var i = 1; i < 11; i ++) {
		if(0 < selectTableBookId[i]) {
			sum += selectTableBookId[i] + ", ";
		}
	}
}

function changeBookTableButton() {
	if(0 == deleteBookFlag) {
		$("#del_grid-table .ui-icon").html("");
		$("#edit_grid-table .ui-icon").html("");
	} else {
		$("#del_grid-table .ui-icon").html("<img id='ui-icon-trash' src='../assets/css/images/user-ui-icon-trash-red.png' width='18' height='20' vertical-align='center' />");
		$("#edit_grid-table .ui-icon").html("<img id='ui-icon-trash' src='../assets/css/images/user-ui-icon-pencil-blue.png' width='18' height='20' vertical-align='center' />");
	}
}

function showBookAddDialog() {
	
	jEditDialog(bookAddDialog, "");
	Mask.Background();
	
	jQuery("#popup_container").jquerymove();
	
	Mask.Background();
	buttonInEditDialog();
}

function showBookEditDialog(selectUniqueBookID) {
	var id = $(selectUniqueBookID).parent().parent().parent().children("td:eq(2)").html();
	var name = $(selectUniqueBookID).parent().parent().parent().children("td:eq(3)").html();
	var borrowed = $(selectUniqueBookID).parent().parent().parent().children("td:eq(4)").html();
	var remarks = $(selectUniqueBookID).parent().parent().parent().children("td:eq(5)").html();
	jEditDialog(bookEditDialog, "");
	
	// to make it can be dragged
	jQuery("#popup_container").jquerymove();
	
	$("#id").val(id);
	$("#name").val(name);
	if(borrowed == "false") {
		$("#tr_borrowed input").attr("checked", false);
		$("#borrowedHidden").val("false");
	} else {
		$("#tr_borrowed input").attr("checked", true);
		$("#borrowedHidden").val("true");
	}
	$("#borrowedHidden").css("display", "none");
	$("#remarks").val(remarks);
	
	Mask.Background();
	buttonInEditDialog();
}

function deleteBookById(selectUniqueBook) {
	var selectUniqueBookID = $(selectUniqueBook).parent().parent().parent().children("td:eq(2)").html();
	
	var bookEditSubmitData = {};
	
	bookEditSubmitData["book.id"] = selectUniqueBookID;
	
	bookEditSubmitData["page.page"] = $("#grid-pager_center .ui-pg-input").val();
	bookEditSubmitData["page.size"] = 10;
	
	var bookEditSubmitUrl = "/openresource-client/book/updateBook?method=deleteBookById";
	
	if(!confirm('删除该书籍吗')) {
		return ;
	}
	
	$.ajax({
		url: bookEditSubmitUrl,
		type: "POST",
		data: confirmData(bookEditSubmitData),
		dataType: "json",
		error:function(data) {
			alert("request error");
		},
		success: function(mydata) {
			if (mydata.bookVo.msg == null || mydata.bookVo.msg == "" || mydata.bookVo.msg == "error") {
				alert("删除不成功");
				$("#grid-pager_center .ui-pg-input").val(1);
				$("#sp_1_grid-pager").html(1);
				drawpages(1, mydata.bookVo.page.max);
				Mask.Close();
			} else {
				refreshBookPage($("#grid-pager_center .ui-pg-input").val());
				$.alerts._hide();
				Mask.Close();
			}
		}
	});
}

function refreshBookPage(currentPage) {
	var data = {};
	data['page'] = {page:currentPage, num:10};
	data['method'] = "getAllBookByPage";
	url = "/openresource-client/book/getAllBookByPage";
	
	showBook(url, data);
}
